package top.zuli.package02.homework14;

public class AccountTest2 {
    public static void main(String[] args) {
        Thread t1 = new Account2();
        Thread t2 = new Account2();
        t1.start();
        t2.start();
    }
}
class Account2 extends Thread{
    private static int money = 0;
    private static Object obj = new Object();
    @Override
    public void run() {
        for (int i = 1; i <=3; i++) {
            synchronized (Account2.class){
                if(money < 3000){
                    try {
                        sleep(250);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    money += 1000;
                    System.out.println(Thread.currentThread().getName()+"：存钱成功。余额为："+money);
                }
            }
        }
    }
}
